//
//  Network.swift
//  ShareMusic
//
//  Created by 胡岩 on 16/5/3.
//  Copyright © 2016年 胡岩. All rights reserved.
//

import UIKit
import Alamofire

class Network: NSObject {
    class internal func networkGet(url:URLStringConvertible, parameters: [String: AnyObject]? = nil, closure:(AnyObject)->()) {
        Alamofire.request(.GET, url, parameters: parameters)
            .responseJSON { response in
                if response.result.isSuccess == false {
                    let alert = UIAlertView.init(title: "提示", message: "网络异常", delegate: nil, cancelButtonTitle: "确定")
                    alert.show()
                }
                if let JSON = response.result.value {
                    closure(JSON)
                }
        }
    }
    
    class internal func networkGetData(url:URLStringConvertible, model:songModel, closure:(AnyObject, songModel)->()) {
        Alamofire.request(.GET, url)
            .responseJSON { response in
                if response.data == nil {
                    let alert = UIAlertView.init(title: "提示", message: "网络异常", delegate: nil, cancelButtonTitle: "确定")
                    alert.show()
                }
                if let data = response.data {
                    closure(data, model)
                }
        }
    }
}
